import featureAbility from '@ohos.ability.featureAbility'
import dataStorage from '@ohos.data.storage'
import HttpUtil from '../utils/httpUtil.js'
import prompt from '@system.prompt';
import router from '@system.router';


export default {
    login(user, callback) {
        HttpUtil.post({
            uri: '/api/login', data: user, success: (data) => {
                console.info("user=" + data);
                HttpUtil.setToken(data.token);
                callback(data);
            }
        });
    },

    getContacts(callback) {
        HttpUtil.get({
            uri: '/api/getAllContacts', success: (data) => {
                console.info("user=" + data);
                callback(data);
            }
        });
    },
    async test() {
        var context = featureAbility.getContext();
        var myPath;
        await context.getFilesDir().then((path) => {
            console.info('File directory obtained. Data:' + path);
            myPath = path;
        }).catch((error) => {
            console.error('Failed to obtain the file directory. Cause: ' + error.message);
        })
        let storage = dataStorage.getStorageSync(myPath + '/iss')
        storage.putSync('startup', 'auto')
        storage.flushSync()
    },
    async zz() {
        var myPath;
        await featureAbility.getContext().getFilesDir().then((path) => {
            myPath = path + '/edu';
            console.info('File directory obtained. Data:' + myPath);
        }).catch((error) => {
            console.error('Failed to obtain the file directory. Cause: ' + error.message);
        })
        let storage = dataStorage.getStorageSync(myPath);
        let token = storage.getSync('token', 'noToken');
        prompt.showToast({
            message: token
        })
        //        router.push({
        //            uri: 'pages/splash/splash'
        //        })
    }
}